package com.baymax.test.scene.demo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import com.baymax.test.scene.BaseScene
import com.baymax.test.scene.addButton

import com.baymax.test.scene.newSceneFlexContainer
import com.google.common.eventbus.EventBus
import com.google.common.eventbus.Subscribe
import java.util.logging.ConsoleHandler
import java.util.logging.Handler
import java.util.logging.Level
import java.util.logging.LogRecord
import java.util.logging.Logger

class GuavaScene : BaseScene() {
   val guavaLogger = Logger.getLogger("GuavaScene")


    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        val eventBus = EventBus()
        eventBus.register(this)
        lifecycle.addObserver(object :DefaultLifecycleObserver{
            override fun onDestroy(owner: LifecycleOwner) {
                super.onDestroy(owner)
                eventBus.unregister(this)
            }
        })
        return p1.newSceneFlexContainer {
            addButton("post hello") {
                eventBus.post("hell  world")
                guavaLogger.info("post message")
            }
        }
    }

    @Subscribe
    public fun hear(str:String){
        Logger.getGlobal().info("global hear")
    }
}